Skip to content

Revert "fix: construct User object from flat AuthResponse fields in auth store"#79

Merged
MaximumTrainer merged 1 commit intomainfrom
revert-76-copilot/fix-build-issue
Apr 18, 2026
Merged

Revert "fix: construct User object from flat AuthResponse fields in auth store"#79
MaximumTrainer merged 1 commit intomainfrom
revert-76-copilot/fix-build-issue

Conversation

@MaximumTrainer
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings April 18, 2026 07:30
@MaximumTrainer MaximumTrainer merged commit 078f1c9 into main Apr 18, 2026
9 checks passed
@MaximumTrainer MaximumTrainer deleted the revert-76-copilot/fix-build-issue branch April 18, 2026 07:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reverts a previous frontend change that constructed a User from a flat AuthResponse, switching the frontend back to expecting a nested user object in auth responses.

Changes:

  • Removed login/register unit tests that validated behavior with a flat AuthResponse.
  • Changed AuthResponse TypeScript type from flat user fields to { token, user }.
  • Updated the auth store to directly use response.user in login() / register() and persist it to localStorage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
frontend/src/views/tests/auth.store.test.ts Removes login/register coverage related to flat auth responses.
frontend/src/types/index.ts Changes AuthResponse shape to include a nested user.
frontend/src/store/auth.ts Updates login/register to read and persist response.user (no mapping).
Comments suppressed due to low confidence (1)

frontend/src/views/tests/auth.store.test.ts:102

  • The login/register unit tests that asserted auth state + localStorage persistence were removed. With this change set (and especially given the auth response shape is being modified), there’s no longer test coverage ensuring login()/register() populate user, token, and storage correctly. Consider reintroducing tests for the current expected response contract (flat vs nested) so regressions in auth flows are caught.
describe('useAuthStore – mocking the SAML user directly (unit-test style)', () => {
  beforeEach(() => {
    setActivePinia(createPinia())
    localStorage.clear()
    vi.resetAllMocks()
  })

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

username: string
email: string
role: UserRole
user: User
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AuthResponse was changed to { token, user }, but the backend currently returns a flat auth response (token, userId, username, email, role) (see backend/.../AuthDto.kt:30-36). With this type shape, frontend code will compile but response.user will be undefined at runtime unless the backend contract is also changed. Either revert this TS type back to the flat shape or update the backend DTO/controller to return user: { ... } (including createdAt) consistently.

Suggested change
user: User
userId: number
username: string
email: string
role: UserRole

Copilot uses AI. Check for mistakes.
Comment on lines 45 to +58
async function login(credentials: LoginRequest): Promise<void> {
const response = await authApi.login(credentials)
token.value = response.token
const loginUser = userFromAuthResponse(response)
user.value = loginUser
user.value = response.user
localStorage.setItem('token', response.token)
localStorage.setItem('user', JSON.stringify(loginUser))
localStorage.setItem('user', JSON.stringify(response.user))
}

async function register(payload: RegisterRequest & { role?: UserRole }): Promise<void> {
const response = await authApi.register(payload)
token.value = response.token
const regUser = userFromAuthResponse(response)
user.value = regUser
user.value = response.user
localStorage.setItem('token', response.token)
localStorage.setItem('user', JSON.stringify(regUser))
localStorage.setItem('user', JSON.stringify(response.user))
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

login() and register() now read response.user and persist it. Given the backend auth endpoints currently return flat fields (no user object), this will set user.value to undefined, store invalid JSON, and leave isAuthenticated false after a successful login/register. Consider mapping the backend response into a User (e.g., reintroduce a userFromAuthResponse transform or do the mapping in @/api/auth) or change the backend response to include user.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants